package org.example.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.example.common.configs.exception.ErrorConstants;
import org.example.common.constants.WGConstant;

import java.util.Objects;

@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
@AllArgsConstructor
@Getter
public enum WGErrorEnum {
    /**
     * 返回枚举
     * 0010-0999 系统
     * 1000-1009 日志
     * 1010-1019 字典
     * 1020-1039 用户
     * 1040-1049 角色
     * 1050-1059 组织
     * 1060-1069 菜单
     * 1070 - 1090 curve plan
     * 1090 - 1100 project
     * 1111 - 1120 team
     * 1121 - 1130 application
     * 1131 - 1140 admin
     * 1141 - 1200 curve plan
     * 1201 - 1210 rate
     * 1211 - 1220 resource
     * 1221 - 1240 tag
     * 1241 - 1270 所有图表
     * 1271 - 1300 buffer
     *
     * @author weigang1
     */

    e_0010("0010", "params err"),
    e_0011("0011", "json format err"),
    e_0020("0020", "query object is not exist"),
    e_0021("0021", "ID字段不能为空"),
    e_0022("0022", "当前财年未配置节假日信息"),
    e_0023("0023", "暂未实现"),
    e_0024("0024", "无权限"),
    e_0025("0025", "用户未登录"),
    e_0026("0026", "上传Excel失败，数据类型不匹配，row: %s，column: %s，正确的类型: %s"),
    e_0027("0027", "上传Excel失败"),
    e_0028("0028", "并发冲突，请稍候重试"),
    e_0029("0029", "处于Outage期间 %s，不能登录"),

    e_1011("1011", "字典标识已存在，不允许重复添加"),
    e_1012("1012", "存在字典项，不允许删除"),

    e_1020("1020", "获取用户信息失败"),
    e_1021("1021", "获取用户信息失败：初始化LDAP上下文失败"),
    e_1022("1022", "获取用户信息失败：用户不存在"),
    e_1023("1023", "获取用户信息失败：invalid token"),
    e_1024("1024", "获取用户信息失败：invalid it code"),
    e_1025("1025", "获取用户信息失败：用户在AD中不存在"),
    e_1026("1026", "获取用户信息失败：用户未登录"),
    e_1027("1027", "用户登录失败：用户名密码错误"),
    e_1028("1028", "用户登录失败：用户不存在，请找管理员添加用户"),
    e_1029("1029", "重置密码失败：当前用户未登录"),
    e_1030("1030", "用户名已存在不允许重复添加"),
    e_1031("1031", "该用户尚未加入组织"),
    e_1032("1032", "创建用户失败：部门不存在"),
    e_1033("1033", "创建用户失败：角色不存在"),
    e_1034("1034", "创建用户失败：team不存在"),
    e_1035("1035", "更新用户失败：用户不存在"),
    e_1036("1036", "系统用户不允许删除"),
    e_1037("1037", "该用户已在角色中添加，不允许删除"),
    e_1038("1038", "该用户已在Team中添加，不允许删除"),
    e_1039("1039", "用户不存在"),
    e_1040("1040", "该用户不在部门范围内: %s"),


    e_1048("1048", "系统角色不允许删除"),
    e_1049("1049", "该角色标识已存在，不允许重复添加"),
    e_1042("1042", "workload阈值不存在"),

    e_1051("1051", "存在子组织，不允许删除"),
    e_1052("1052", "该组织下存在用户，不允许删除"),

    e_1061("1061", "存在子菜单，不允许删除"),


    e_1070("1070", "用户的curve plan已经存在"),
    e_1071("1071", "Curve Plan不存在"),
    e_1072("1072", "Curve Plan项目 Track Info/应用/admin信息不完整"),
    e_1073("1073", "Curve Plan项目预算信息不完整"),
    e_1074("1074", "加载Curve Plan Excel模板失败"),
    e_1075("1075", "添加Curve Plan，用户不存在: %s"),
    e_1076("1076", "添加Curve Plan，项目Track Info/应用/admin 不存在"),
    e_1077("1077", "上传curve plan失败：读取文件失败"),
    e_1078("1078", "上传Excel失败：未知的Type类型"),
    e_1079("1079", "管理员或者项目track lead/Admin Owner/Application Owner 允许创建更新Curve Plan"),
    e_1080("1080", "Curve Plan重复, %s"),
    e_1081("1081", "以下用户的Curve Plan已经commit或者正在等待审核，不能commit, %s"),
    e_1082("1082", "只能创建自己部门内用户的Curve Plan，以下用户不在部门范围内: %s"),
    e_1083("1083", "Curve Plan统计信息不存在，更新失败"),
    e_1084("1084", "Curve Plan更新失败，未知的Curve Type"),
    e_1085("1085", "创建Curve Plan失败，以下Admin不存在: %s"),
    e_1086("1086", "Project Track Info Name，Project ID must be filled in before curve plan is committed"),
    e_1087("1087", "Commit Curve Plan, Admin信息不完整"),
    e_1088("1088", "Commit Curve Plan, Application信息不完整"),
    e_1089("1089", "待审核的Curve Plan不能更新"),


    e_1090("1090", "Project id exist"),
    e_1091("1091", "请先删除关联的Curve Plan，再删除此信息"),
    e_1092("1092", "Project id not exist"),
    e_1093("1093", "Project id 重复"),
    e_1094("1094", "Track Internal Budget + Track External Budget ≠ Track Total Labor Budget"),
    e_1095("1095", "Start Date > Close Date"),
    e_1096("1096", "Track Lead只允许是自己"),
    e_1097("1097", "只能创建自己部门内的Track Lead，以下用户不再部门范围内: %s"),
    e_1098("1098", "Track info title 重复: %s"),


    e_1111("1111", "Team Lead用户不存在"),
    e_1112("1112", "更新Team失败，Team不存在"),
    e_1113("1113", "Team名字不存在"),

    e_1121("1121", "Application Not Exist"),
    e_1122("1122", "Application id 重复: %s"),
    e_1123("1123", "Application id 已存在: %s"),
    e_1124("1124", "加载Application Excel模板失败"),
    e_1125("1125", "上传Application失败：读取文件失败"),

    e_1131("1131", "admin name 不允许重复"),
    e_1132("1132", "Admin Not Exist"),
    e_1133("1133", "上传Admin失败：读取文件失败"),
    e_1134("1134", "Admin name 已存在: %s"),
    e_1135("1135", "只允许保存自己的Admin信息"),


    e_1201("1201", "start date > end date"),
    e_1202("1202", "开始日期小于之前记录开始日期"),
    e_1203("1203", "日期格式错误"),
    e_1204("1204", "只允许删除该用户最后一条Rate记录"),

    e_1141("1141", "待审核的Curve Plan不能删除"),
    e_1142("1142", "以下用户的Curve Plan超出Workload阈值， %s"),
    e_1143("1143", "下列用户不属于管理组，不能进行Curve Plan审批， %s"),
    e_1144("1144", "Curve Plan不是待审核状态，不能审核"),
    e_1145("1145", "Curve Plan待审核记录不存在"),
    e_1146("1146", "当前用户不在指定的Curve Plan审核人列表内，审核人列表: %s"),
    e_1147("1147", "审核Curve Plan操作非法，仅支持通过或者拒绝或者撤回"),
    e_1148("1148", "创建Curve Plan失败，以下Track Info不存在: %s"),

    e_1211("1211", "该用户当月已填写Resource plan"),
    e_1212("1212", "当前用户无查看该Resource plan权限"),
    e_1213("1213", "当前用户无操作该Resource plan权限"),
    e_1214("1214", "Project id 不能为空"),
    e_1215("1215", "admin id 不能为空"),
    e_1216("1216", "application id 不能为空"),

    e_1241("1241", "团队下没有用户"),


    e_9999(WGConstant.UNKNOWN_ERROR, "unknown err"),
    ;

    private final String code;
    private final String msg;

    public static WGErrorEnum parse(String code) {
        return parse(code, e_9999);
    }

    public static WGErrorEnum parse(String code, WGErrorEnum defaultError) {
        for (WGErrorEnum value : values()) {
            if (Objects.equals(value.code, code)) {
                return value;
            }
        }
        return defaultError;
    }


}
